package cn.edu.neu.studentmsg_java.service.impl;

import cn.edu.neu.studentmsg_java.dao.CourseDao;
import cn.edu.neu.studentmsg_java.dao.SelectionDao;
import cn.edu.neu.studentmsg_java.model.Selection;
import cn.edu.neu.studentmsg_java.service.SelectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SelectionServiceImpl implements SelectionService {

    @Autowired
    private SelectionDao selectionDao;
    @Autowired
    private CourseDao courseDao;

    @Override
    public List<Selection> findSelectionPartByStudentId(Selection selection) {
        return selectionDao.selectSelectionPartByStudentId(selection);
    }

    @Override
    public int addSelectionByStudentId(Selection selection) {
        Integer course_id = courseDao.selectCourseIdByCourseName(selection.getCourse_name());
        if (course_id != null) {
            return selectionDao.insertSelectionByStudentId(selection.getStudent_id(), course_id);
        }
        return 0;
    }

    @Override
    public int removeSelectionByCourseIdAndStudentId(Selection selection) {
        return selectionDao.deleteSelectionByCourseIdAndStudentId(selection);
    }

    @Override
    public int modifySelectionFinalScore(Selection selection) {
        return selectionDao.updateSelectionFinalScore(selection);
    }
}
